import 'package:flutter/material.dart';
import 'package:jiajia_diy/diyProject/diy.dart';
import 'dart:io';
import 'package:jiajia_diy/pages/diy_details_page.dart';
import 'dart:async';
import 'dart:math';

/*
首页列表中每个diy的UI布局
 */
class DiyItemUI extends StatelessWidget {
  DiyItemUI(this.diyItem);
  Diy diyItem;
  List<String> images = List.generate(12, (index) {
    return 'images/$index.jpg';
  });

  @override
  Widget build(BuildContext context) {
    //diy活动信息展示布局
    var column = new Container(
      padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          new Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Text(
                diyItem.name,
                style:
                    new TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
              ),
              new Text('  ${diyItem.date}'),
            ],
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Row(
                children: <Widget>[
                  new Icon(
                    Icons.person,
                    size: 16.0,
                    color: Colors.grey[700],
                  ),
                  new Text('  ${diyItem.leader}',style: new TextStyle( color: Colors.grey[600]),)
                ],
              ),
              new Row(
                children: <Widget>[
                  new Icon(
                    Icons.location_on,
                    size: 16.0,
                    color: Colors.grey[700],
                  ),
                  new Text('  ${diyItem.place}',style: new TextStyle( color: Colors.grey[700]),)
                ],
              ),
            ],
          ),
        ],
      ),
    );

    //单个diy项目的展示布局
    int i = 0;
    var content = new Container(
      height: 250.0,
      padding: const EdgeInsets.all(4.0),
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new Expanded(
            flex: 3,
            child: new Image.file(
              File( diyItem.path),
              height: 380.0,
              width: 400.0,
              //package: destination.assetPackage,
              fit: BoxFit.cover,
            ),
          ),
          new Expanded(
            child: column,
          ),
          new Padding(
            padding: const EdgeInsets.only(left: 4.0),
            child: new Text(
              '￥ ${diyItem.profit}',
              style: new TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 18.0,
                  color: Theme.of(context).primaryColor),
            ),
          ),
        ],
      ),
    );

    //将整个diy项目布局放在一个card里
    return new Card(
      margin: const EdgeInsets.fromLTRB(18.0, 18.0, 18.0, 8.0),
      child: content,
    );
  }
}
